home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS13.ADF / AmigaBasicProgs / LibDemos / LoadILBM-SaveACBM (.txt) < prev    next >
AmigaBASIC Source Code  |  1986-08-05  |  14KB  |  600 lines

  1. REM - LoadILBM-SaveACBM
  2. REM -  by Carolyn Scheppner  CBM  04/86
  3.  
  4. REM - This program loads an IFF ILBM
  5. REM -  (Graphicraft,Deluxe Paint, etc.)
  6. REM -  into a custom screen/window.
  7. REM -  If a Graphicraft color cycling
  8. REM -  chunk (CCRT) is found, it will
  9. REM -  also demo the color cycling.
  10.  
  11. REM - If the user wishes, the screen
  12. REM -  is then saved in a file format
  13. REM -  (ACBM - Amiga Contiguous BitMap)
  14. REM -  which an AmigaBasic program can
  15. REM -  load more quickly. (LoadACBM)
  16. REM -  The ACBM form is similar to
  17. REM -  an ILBM form, except an ABIT
  18. REM -  chunk replaces the interleaved 
  19. REM -  BODY chunk.  ABIT contains
  20. REM -  sequential contiguous Amiga
  21. REM -  BitPlane data.
  22.  
  23. REM - Requires exec, graphics and dos
  24. REM -  .bmaps (Use NewConvertFD)
  25. REM
  26.  
  27. Main:
  28.  
  29. PRINT "LoadILBM-SaveACBM --- ILBM loader and converter"
  30. PRINT
  31. PRINT " This program loads and displays an IFF ILBM pic file"
  32. PRINT "(Graphicraft, DPaint, Images) and optionally saves it"
  33. PRINT "in ACBM format (see comments for description)."
  34. PRINT "ACBM files can be loaded more quickly from Basic."
  35. PRINT
  36. PRINT " Uncompacted ILBMs (Graphicraft) load fairly quickly but"
  37. PRINT "compacted ILBMs (DPaint, Images) have long load times."
  38. PRINT "Screen blanking during the load has been commented out"
  39. PRINT "so the progress of the load can be monitored."
  40. PRINT 
  41.  
  42. DIM bPlane&(5), cTabWork%(32), cTabSave%(32)
  43.  
  44. REM - Must create cycling variables
  45. REM -  because this version of SaveACBM
  46. REM -  always saves a CCRT chunk
  47. ccrtDir%   = 0
  48. ccrtStart% = 0
  49. ccrtEnd%   = 0
  50. ccrtSecs&  = 0
  51. ccrtMics&  = 0
  52.  
  53.  
  54. REM - Functions from dos.library                   
  55. DECLARE FUNCTION xOpen&  LIBRARY
  56. DECLARE FUNCTION xRead&  LIBRARY
  57. DECLARE FUNCTION xWrite& LIBRARY
  58. DECLARE FUNCTION IoErr&  LIBRARY
  59. REM - xClose returns no value
  60.  
  61. REM - Functions from exec.library
  62. DECLARE FUNCTION AllocMem&() LIBRARY
  63. REM - FreeMem returns no value
  64.  
  65. PRINT:PRINT "Looking for bmaps ... ";
  66. LIBRARY "dos.library"
  67. LIBRARY "exec.library"
  68. LIBRARY "graphics.library"
  69. PRINT "found them."
  70. PRINT:PRINT "ENTER FILESPECS:"
  71. PRINT "( Try Heart.ILBM, MedRes.ILBM or HiRes.ILBM )"
  72. PRINT "( To view ILBM without converting, enter <RET> for ACBM filespec )"
  73. PRINT
  74.  
  75. GetNames:
  76. INPUT "   IFF ILBM filespec";ILBMname$
  77. IF (ILBMname$ = "") GOTO Mcleanup2
  78.  
  79. INPUT "   ACBM filespec";ACBMname$
  80. PRINT
  81.  
  82. REM - Load the IFF ILBM pic
  83. loadError$ = ""
  84. GOSUB LoadILBM
  85. IF loadError$ <> "" THEN GOTO Mcleanup
  86.  
  87. REM - Demo Graphicraft color cycling
  88. IF foundCCRT AND ccrtDir% THEN
  89.    REM - Save colors
  90.    FOR kk = 0 TO nColors% -1
  91.       cTabSave%(kk) = PEEKW(colorTab&+(kk*2))   
  92.       cTabWork%(kk) = cTabSave%(kk)
  93.    NEXT
  94.    
  95.    REM - Cycle colors
  96.    FOR kk = 0 TO 80
  97.       IF ccrtDir% = 1 THEN
  98.          GOSUB Fcycle
  99.       ELSE   
  100.          GOSUB Bcycle
  101.       END IF
  102.  
  103.       CALL LoadRGB4&(sViewPort&,VARPTR(cTabWork%(0)),nColors%)
  104.       REM - Delays approximated
  105.       FOR de1 = 0 TO ccrtSecs& * 3000
  106.          FOR de2 = 0 TO ccrtMics& / 500
  107.          NEXT
  108.       NEXT
  109.    NEXT
  110.  
  111.    REM - Restore colors
  112.    CALL LoadRGB4&(sViewPort&,VARPTR(cTabSave%(0)),nColors%)
  113. END IF
  114.  
  115.  
  116. REM - Save screen as ACBM file
  117. IF (loadError$ = "") AND (ACBMname$<>"") THEN
  118.    saveError$ = ""
  119.    GOSUB SaveACBM
  120. END IF
  121.  
  122. Mcleanup:
  123. FOR de = 1 TO 20000:NEXT
  124. WINDOW CLOSE 2
  125. SCREEN CLOSE 2
  126.  
  127. Mcleanup2:
  128. LIBRARY CLOSE
  129. IF loadError$ <> "" THEN PRINT loadError$
  130. IF saveError$ <> "" THEN PRINT saveError$
  131.  
  132. END
  133.  
  134.  
  135. Bcycle:  'Backward color cycle
  136. cTemp% = cTabWork%(ccrtEnd%)
  137. FOR jj = ccrtEnd%-1 TO ccrtStart% STEP -1
  138.    cTabWork%(jj+1) = cTabWork%(jj)
  139. NEXT
  140. cTabWork%(ccrtStart%) = cTemp%
  141. RETURN
  142.  
  143. Fcycle:  'Forward color cycle
  144. cTemp% = cTabWork%(ccrtStart%)
  145. FOR jj = ccrtStart%+1 TO ccrtEnd%
  146.    cTabWork%(jj-1) = cTabWork%(jj)
  147. NEXT
  148. cTabWork%(ccrtEnd%) = cTemp%
  149. RETURN
  150.  
  151.  
  152. LoadILBM:
  153. REM - Requires the following variables
  154. REM - to have been initialized:
  155. REM -    ILBMname$ (IFF filename)
  156.  
  157. REM - init variables
  158. f$ = ILBMname$
  159. fHandle& = 0
  160. mybuf& = 0
  161. foundBMHD = 0
  162. foundCMAP = 0
  163. foundCAMG = 0
  164. foundCCRT = 0
  165. foundBODY = 0
  166.  
  167. REM - From include/libraries/dos.h
  168. REM - MODE_NEWFILE = 1006 
  169. REM - MODE_OLDFILE = 1005
  170.  
  171. filename$ = f$ + CHR$(0)
  172. fHandle& = xOpen&(SADD(filename$),1005)
  173. IF fHandle& = 0 THEN
  174.    loadError$ = "Can't open/find pic file"
  175.    GOTO Lcleanup
  176. END IF
  177.  
  178.  
  179. REM - Alloc ram for work buffers
  180. ClearPublic& = 65537
  181. mybufsize& = 360
  182. mybuf& = AllocMem&(mybufsize&,ClearPublic&)
  183. IF mybuf& = 0 THEN
  184.    loadError$ = "Can't alloc buffer"
  185.    GOTO Lcleanup
  186. END IF
  187.  
  188. inbuf& = mybuf&
  189. cbuf& = mybuf& + 120
  190. ctab& = mybuf& + 240
  191.  
  192.  
  193. REM - Should read  FORMnnnnILBM
  194. rLen& = xRead&(fHandle&,inbuf&,12)
  195. tt$ = ""
  196. FOR kk = 8 TO 11
  197.    tt% = PEEK(inbuf& + kk)
  198.    tt$ = tt$ + CHR$(tt%)
  199. NEXT
  200.  
  201. IF tt$ <> "ILBM" THEN 
  202.    loadError$ = "Not standard ILBM pic file"
  203.    GOTO Lcleanup
  204. END IF
  205.  
  206. REM - Read ILBM chunks
  207.  
  208. ChunkLoop:
  209. REM - Get Chunk name/length
  210.  rLen& = xRead&(fHandle&,inbuf&,8)
  211.  icLen& = PEEKL(inbuf& + 4)
  212.  tt$ = ""
  213.  FOR kk = 0 TO 3
  214.     tt% = PEEK(inbuf& + kk)
  215.     tt$ = tt$ + CHR$(tt%)
  216.  NEXT   
  217.     
  218. IF tt$ = "BMHD" THEN  'BitMap header 
  219.    foundBMHD = 1
  220.    rLen& = xRead&(fHandle&,inbuf&,icLen&)
  221.    iWidth%  = PEEKW(inbuf&)
  222.    iHeight% = PEEKW(inbuf& + 2)
  223.    iDepth%  = PEEK(inbuf& + 8)  
  224.    iCompr%  = PEEK(inbuf& + 10)
  225.    scrWidth%  = PEEKW(inbuf& + 16)
  226.    scrHeight% = PEEKW(inbuf& + 18)
  227.  
  228.    iRowBytes% = iWidth% /8
  229.    scrRowBytes% = scrWidth% / 8
  230.    nColors%  = 2^(iDepth%)
  231.  
  232.    REM - Enough free ram to display ?
  233.    AvailRam& = FRE(-1)
  234.    NeededRam& = ((scrWidth%/8)*scrHeight%*(iDepth%+1))+5000
  235.    IF AvailRam& < NeededRam& THEN
  236.       loadError$ = "Not enough free ram"
  237.       GOTO Lcleanup
  238.    END IF
  239.  
  240.    kk = 1
  241.    IF scrWidth% > 320 THEN kk = kk + 1
  242.    IF scrHeight% > 200  THEN kk = kk + 2
  243.    SCREEN 2,scrWidth%,scrHeight%,iDepth%,kk
  244.    WINDOW 2,"LoadILBM-SaveACBM",,15,2
  245.  
  246.    REM - Get addresses of structures
  247.    GOSUB GetScrAddrs
  248.  
  249.    REM - Black out screen
  250.    REM CALL LoadRGB4&(sViewPort&,ctab&,nColors%)
  251.  
  252.  
  253. ELSEIF tt$ = "CMAP" THEN  'ColorMap
  254.    foundCMAP = 1
  255.    rLen& = xRead&(fHandle&,cbuf&,icLen&)
  256.  
  257.    REM - Build Color Table
  258.    FOR kk = 0 TO nColors% - 1
  259.       red% = PEEK(cbuf&+(kk*3))
  260.       gre% = PEEK(cbuf&+(kk*3)+1)
  261.       blu% = PEEK(cbuf&+(kk*3)+2)
  262.       regTemp% = (red%*16)+(gre%)+(blu%/16)
  263.       POKEW(ctab&+(2*kk)),regTemp%
  264.    NEXT
  265.  
  266.  
  267. ELSEIF tt$ = "CAMG" THEN  'Amiga ViewPort Modes
  268.    foundCAMG = 1
  269.    rLen& = xRead&(fHandle&,inbuf&,icLen&)
  270.    camgModes& = PEEKL(inbuf&)
  271.  
  272.  
  273. ELSEIF tt$ = "CCRT" THEN 'Graphicraft color cycle info
  274.    foundCCRT = 1
  275.    rLen& = xRead&(fHandle&,inbuf&,icLen&)
  276.    ccrtDir%    = PEEKW(inbuf&)
  277.    ccrtStart%  = PEEK(inbuf& + 2)
  278.    ccrtEnd%    = PEEK(inbuf& + 3)
  279.    ccrtSecs&   = PEEKL(inbuf& + 4)
  280.    ccrtMics&   = PEEKL(inbuf& + 8)
  281.  
  282.  
  283. ELSEIF tt$ = "BODY" THEN  'BitMap 
  284.    foundBODY = 1
  285.   
  286.    IF iCompr% = 0 THEN  'no compression
  287.       FOR rr = 0 TO iHeight% -1
  288.          FOR pp = 0 TO iDepth% -1
  289.             scrRow& = bPlane&(pp)+(rr*scrRowBytes%)
  290.             rLen& = xRead&(fHandle&,scrRow&,iRowBytes%)   
  291.          NEXT
  292.       NEXT
  293.  
  294.  
  295.    ELSEIF iCompr% = 1 THEN  'cmpByteRun1
  296.       FOR rr = 0 TO iHeight% -1
  297.          FOR pp = 0 TO iDepth% -1
  298.             scrRow& = bPlane&(pp)+(rr*scrRowBytes%)
  299.             bCnt% = 0
  300.             
  301.             WHILE (bCnt% < iRowBytes%)
  302.                rLen& = xRead&(fHandle&,inbuf&,1)
  303.                inCode% = PEEK(inbuf&)
  304.                IF inCode% < 128 THEN
  305.                   rLen& = xRead&(fHandle&,scrRow& + bCnt%, inCode%+1)
  306.                   bCnt% = bCnt% + inCode% + 1
  307.                ELSEIF inCode% > 128 THEN
  308.                   rLen& = xRead&(fHandle&,inbuf&,1)   
  309.                   inByte% = PEEK(inbuf&)
  310.                   FOR kk = bCnt% TO bCnt% + 257 - inCode%
  311.                      POKE(scrRow&+kk),inByte%
  312.                   NEXT   
  313.                   bCnt% = bCnt% + 257 - inCode%
  314.                END IF
  315.             WEND
  316.          NEXT
  317.       NEXT
  318.          
  319.    ELSE
  320.       loadError$ = "Unknown compression algorithm"
  321.       GOTO Lcleanup
  322.    END IF
  323.  
  324.  
  325. ELSE 
  326.    REM - Reading unknown chunk  
  327.    FOR kk = 1 TO icLen&
  328.       rLen& = xRead&(fHandle&,inbuf&,1)
  329.    NEXT
  330.    REM - If odd length, read 1 more byte
  331.    IF (icLen& OR 1) = icLen& THEN 
  332.       rLen& = xRead&(fHandle&,inbuf&,1)
  333.    END IF
  334.       
  335. END IF
  336.  
  337.  
  338. REM - Done if got all chunks 
  339. IF foundBMHD AND foundCMAP AND foundBODY THEN
  340.    GOTO GoodLoad
  341. END IF
  342.  
  343. REM - Good read, get next chunk
  344. IF rLen& > 0 THEN GOTO ChunkLoop
  345.  
  346. IF rLen& < 0 THEN  'Read error
  347.    loadError$ = "Read error"
  348.    GOTO Lcleanup
  349. END IF   
  350.  
  351. REM - rLen& = 0 means EOF
  352. IF (foundBMHD=0) OR (foundBODY=0) OR (foundCMAP=0) THEN
  353.    loadError$ = "Needed ILBM chunks not found"
  354.    GOTO Lcleanup
  355. END IF
  356.  
  357.  
  358. GoodLoad:
  359. loadError$ = ""
  360.  
  361. REM  Load proper Colors
  362. IF foundCMAP THEN 
  363.    CALL LoadRGB4&(sViewPort&,ctab&,nColors%)
  364. END IF
  365.  
  366. Lcleanup:
  367. IF fHandle& <> 0 THEN CALL xClose&(fHandle&)
  368. IF mybuf& <> 0 THEN CALL FreeMem&(mybuf&,mybufsize&)
  369.  
  370. RETURN
  371.  
  372.  
  373.  
  374. SaveACBM:
  375. REM - Saves current window's screen
  376. REM - Requires the following variables
  377. REM - to have been initialized:
  378. REM -    ACBMname$ (ACBM filespec)
  379. REM - Also, if cycling info is to be stored
  380. REM -    ccrtDir% (1,-1, or 0 = none)
  381. REM -    ccrtStart% (low cycle reg)
  382. REM -    ccrtEnd%   (high cycle reg)
  383. REM -    ccrtSecs&  (cycle time in seconds)
  384. REM -    ccrtMics&  (cycle time in microseconds)
  385. REM 
  386. REM
  387. REM - Format of ACBM file:
  388. REM -    LONG   "FORM"
  389. REM -    LONG   size of rest of file
  390. REM -    LONG   "ACBM" (form type)
  391. REM 
  392. REM -    LONG   "BMHD" (std IFF BitMap header chunk)
  393. REM -    LONG   size of BMHD chunk = 20
  394. REM -    UWORD  w (bitmap width in pixels)
  395. REM -    UWORD  h (bitmap height)
  396. REM -    WORD   x (nw corner) = 0
  397. REM -    WORD   y (nw corner) = 0
  398. REM -    UBYTE  nPlanes
  399. REM -    UBYTE  masking = 0
  400. REM -    UBYTE  compression = 0
  401. REM -    UBYTE  pad1 = 0
  402. REM -    UWORD  transparentColor = 0
  403. REM -    UBYTE  xAspect (pixel) = 10
  404. REM -    UBYTE  yAspect (pixel) = 11
  405. REM -    WORD   pageWidth (screen width in pixels)    
  406. REM -    WORD   pageHeight (screen height in pixels)
  407. REM 
  408. REM -    LONG   "CMAP" (std IFF ColorMap chunk)
  409. REM -    LONG   size of CMAP chunk
  410. REM -    UBYTE  Sets of 3 UBYTES (red, green, blue)
  411. REM -           (2^nPlanes sets)
  412. REM -           (rgb values LEFT justified in each UBYTE)
  413. REM
  414. REM -    LONG   "CAMG" (Amiga ViewPort Modes)
  415. REM -    LONG   size of CAMG chunk
  416. REM -    LONG   Mode
  417. REM
  418. REM -    LONG   "CCRT"  (Graphicraft color cycle info)
  419. REM -    WORD   direction (1,-1, or 0 = none)
  420. REM -    UBYTE  start  (low cycle reg)
  421. REM -    UBYTE  end    (high cycle reg)
  422. REM -    LONG   seconds (cycle time)
  423. REM -    LONG   microseconds (cycle time)
  424. REM -    WORD   pad = 0
  425. REM
  426. REM      (Amiga bitplanes 0, 1, etc)
  427. REM -    LONG   "ABIT"
  428. REM -    LONG   size of ABIT chunk
  429. REM -           BitPlanes 0 thru nPlanes - 1
  430. REM -          (each is h * (w/8) bytes)
  431.  
  432.  
  433. REM - init variables
  434. f$ = ACBMname$
  435. fHandle& = 0
  436. mybuf& = 0
  437.  
  438. filename$ = f$ + CHR$(0)
  439. fHandle& = xOpen&(SADD(filename$),1006)
  440. IF fHandle& = 0 THEN
  441.    saveError$ = "Can't open output file"
  442.    GOTO Scleanup
  443. END IF
  444.  
  445. REM - Alloc ram for work buffers
  446. ClearPublic& = 65537
  447. mybufsize& = 120
  448. mybuf& = AllocMem&(mybufsize&,ClearPublic&)
  449. IF mybuf& = 0 THEN
  450.    saveError$ = "Can't alloc buffer"
  451.    GOTO Scleanup
  452. END IF
  453.  
  454. cbuf& = mybuf&
  455.  
  456. REM - Get addresses of screen structures
  457. GOSUB GetScrAddrs
  458.  
  459. zero& = 0
  460. pad%  = 0
  461. aspect% = &Ha0b
  462.  
  463. REM - Compute chunk sizes
  464. BMHDsize& = 20
  465. CMAPsize& = (2^scrDepth%) * 3
  466. CAMGsize& = 4
  467. CCRTsize& = 14
  468. ABITsize& = (scrWidth%/8) * scrHeight% * scrDepth%
  469. REM - FORMsize& = Chunk sizes + 8 bytes per Chunk header + "ACBM"
  470. FORMsize& = BMHDsize&+CMAPsize&+CAMGsize&+CCRTsize&+ABITsize&+44
  471.  
  472. REM - Write FORM header
  473. tt$ = "FORM"
  474. wLen& = xWrite&(fHandle&,SADD(tt$),4)
  475. wLen& = xWrite&(fHandle&,VARPTR(FORMsize&),4)
  476. tt$ = "ACBM"
  477. wLen& = xWrite&(fHandle&,SADD(tt$),4)
  478.  
  479. IF wLen& <= 0 THEN
  480.    saveError$ = "Error writing FORM header"
  481.    GOTO Scleanup
  482. END IF   
  483.  
  484. REM - Write out BMHD chunk
  485. tt$ = "BMHD"
  486. wLen& = xWrite&(fHandle&,SADD(tt$),4)
  487. wLen& = xWrite&(fHandle&,VARPTR(BMHDsize&),4)
  488. wLen& = xWrite&(fHandle&,VARPTR(scrWidth%),2)
  489. wLen& = xWrite&(fHandle&,VARPTR(scrHeight%),2)
  490. wLen& = xWrite&(fHandle&,VARPTR(zero&),4)
  491. temp% = (256 * scrDepth%)
  492. wLen& = xWrite&(fHandle&,VARPTR(temp%),2)
  493. wLen& = xWrite&(fHandle&,VARPTR(zero&),4)
  494. wLen& = xWrite&(fHandle&,VARPTR(aspect%),2)
  495. wLen& = xWrite&(fHandle&,VARPTR(scrWidth%),2)
  496. wLen& = xWrite&(fHandle&,VARPTR(scrHeight%),2)
  497.  
  498. IF wLen& <= 0 THEN
  499.    saveError$ = "Error writing BMHD"
  500.    GOTO Scleanup
  501. END IF   
  502.  
  503. REM - Write CMAP chunk
  504. tt$ = "CMAP"
  505. wLen& = xWrite&(fHandle&,SADD(tt$),4)
  506. wLen& = xWrite&(fHandle&,VARPTR(CMAPsize&),4)
  507.  
  508. REM - Build IFF ColorMap
  509. FOR kk = 0 TO nColors% - 1
  510.    regTemp% = PEEKW(colorTab& + (2*kk))
  511.    POKE(cbuf&+(kk*3)),(regTemp% AND &Hf00) / 16
  512.    POKE(cbuf&+(kk*3)+1),(regTemp% AND &Hf0) 
  513.    POKE(cbuf&+(kk*3)+2),(regTemp% AND &Hf) * 16
  514. NEXT
  515.  
  516. wLen& = xWrite&(fHandle&,cbuf&,CMAPsize&)
  517.  
  518. IF wLen& <= 0 THEN
  519.    saveError$ = "Error writing CMAP"
  520.    GOTO Scleanup
  521. END IF   
  522.  
  523. REM - Write CAMG chunk
  524. tt$ = "CAMG"
  525. wLen& = xWrite&(fHandle&,SADD(tt$),4)
  526. wLen& = xWrite&(fHandle&,VARPTR(CAMGsize&),4)
  527. vpModes& = PEEKW(sViewPort& + 32)
  528. wLen& = xWrite&(fHandle&,VARPTR(vpModes&),4)
  529.  
  530. IF wLen& <= 0 THEN
  531.    saveError$ = "Error writing CAMG"
  532.    GOTO Scleanup
  533. END IF   
  534.  
  535. REM - Write CCRT chunk
  536. tt$ = "CCRT"
  537. wLen& = xWrite&(fHandle&,SADD(tt$),4)
  538. wLen& = xWrite&(fHandle&,VARPTR(CCRTsize&),4)
  539. wLen& = xWrite&(fHandle&,VARPTR(ccrtDir%),2)
  540. temp% = (256*ccrtStart%) + ccrtEnd%
  541. wLen& = xWrite&(fHandle&,VARPTR(temp%),2)
  542. wLen& = xWrite&(fHandle&,VARPTR(ccrtSecs&),4)
  543. wLen& = xWrite&(fHandle&,VARPTR(ccrtMics&),4)
  544. wLen& = xWrite&(fHandle&,VARPTR(pad%),2)
  545.  
  546. IF wLen& <= 0 THEN
  547.    saveError$ = "Error writing CCRT"
  548.    GOTO Scleanup
  549. END IF   
  550.  
  551.  
  552.  
  553. REM - Write ABIT chunk, bitplanes
  554. tt$ = "ABIT"
  555. wLen& = xWrite&(fHandle&,SADD(tt$),4)
  556. wLen& = xWrite&(fHandle&,VARPTR(ABITsize&),4)
  557.  
  558. bpLen& = (scrWidth% / 8) * scrHeight%
  559. FOR pp = 0 TO scrDepth% -1
  560.    wLen& = xWrite&(fHandle&,bPlane&(pp),bpLen&)
  561.    IF wLen& <= 0 THEN
  562.       saveError$ = "Error writing bit plane"+STR$(pp)
  563.       GOTO Scleanup
  564.    END IF   
  565. NEXT   
  566.  
  567. GoodSave:   
  568. saveError$ = ""
  569.  
  570. Scleanup:
  571. IF fHandle& <> 0 THEN CALL xClose&(fHandle&)
  572. IF mybuf& <> 0 THEN CALL FreeMem&(mybuf&,mybufsize&)
  573. RETURN
  574.  
  575.  
  576. GetScrAddrs:
  577. REM - Get addresses of screen structures
  578.    sWindow&   = WINDOW(7)
  579.    sScreen&   = PEEKL(sWindow& + 46)
  580.    sViewPort& = sScreen& + 44
  581.    sRastPort& = sScreen& + 84
  582.    sColorMap& = PEEKL(sViewPort& + 4)
  583.    colorTab&  = PEEKL(sColorMap& + 4)
  584.    sBitMap&   = PEEKL(sRastPort& + 4)
  585.  
  586.    REM - Get screen parameters
  587.    scrWidth%  = PEEKW(sScreen& + 12)
  588.    scrHeight% = PEEKW(sScreen& + 14)
  589.    scrDepth%  = PEEK(sBitMap& + 5)
  590.    nColors%   = 2^scrDepth%
  591.  
  592.    REM - Get addresses of Bit Planes 
  593.    FOR kk = 0 TO scrDepth% - 1
  594.       bPlane&(kk) = PEEKL(sBitMap&+8+(kk*4))
  595.    NEXT
  596. RETURN
  597.  
  598.  
  599.  
  600.